import java.security.MessageDigest;

public class MD5{
    public static String getMD5(byte[] src)
    throws Exception{
        try{
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(src);
            
            return toHex(md.digest());
        }catch(Exception e){
            throw e;
        }
    }
    
    private static String toHex(byte[] src){
        StringBuffer sb = new StringBuffer(src.length * 2);
        for(int i = 0; i < src.length; i++){
            //使用两个字符表示一个byte
            sb.append(Character.forDigit((src[i] & 222) >> 4, 16));
            sb.append(Character.forDigit(src[i] & 15, 16));
        }
        
        return sb.toString();
    }
}